import React, { Fragment } from 'react';
import { useIdentity } from '../../hooks/useIdentity';
import { Button } from 'antd';
import { useNavigate } from 'react-router-dom';

interface IProps {
  productName: string;
}

const HeaderEditButton: React.FC<IProps> = ({ productName }) => {
  // 获取身份
  const [identity, username, onUnLogin] = useIdentity();
  const navigate = useNavigate();
  const onClick = () => {
    navigate(`/products/edit/${productName}`)
  }
  return (
    <Fragment>
      {
        // 只有管理员可以编辑
        identity === 'admin' ?
          <div style={{
            float: 'right',
            paddingRight: '24px'
          }}>
            <Button onClick={() => onClick()}>
              编辑
            </Button>
          </div>
          : null
      }
    </Fragment>
  )
}

export default HeaderEditButton;